package com.shuoyue.ycgk.ui.mine.mynote.info;

import com.shuoyue.ycgk.base.BaseModel;
import com.shuoyue.ycgk.base.BasePresenter;
import com.shuoyue.ycgk.base.BaseResult;
import com.shuoyue.ycgk.base.BaseView;
import com.shuoyue.ycgk.entity.QuestionParent;
import com.shuoyue.ycgk.entity.UserAnswerPager;
import com.shuoyue.ycgk.net.RetrofitClient;
import com.shuoyue.ycgk.net.base.ApiSubscriber;
import com.shuoyue.ycgk.net.gsondefaultadapter.Optional;

import java.util.List;

import io.reactivex.Observable;

public interface MyNoteInfoContract {
    interface View extends BaseView {
        void setQuestion(List<QuestionParent> question);
    }

    class Presenter extends BasePresenter<View> {
        Model model = new Model();


        public void getQuestionInfo(int questionId) {
            apply(model.getQuestionInfo(questionId))
                    .subscribe(new ApiSubscriber<Optional<List<QuestionParent>>>(mView, this) {
                        @Override
                        public void onNext(Optional<List<QuestionParent>> optional) {
                            super.onNext(optional);
                            mView.setQuestion(optional.get());
                        }
                    });
        }

    }

    class Model extends BaseModel {
        Observable<BaseResult<List<QuestionParent>>> getQuestionInfo(int questionId) {
            return RetrofitClient.getInstance().getApi().getQuestionInfo(questionId);
        }
    }
}
